#include <iostream>

using namespace std;
bool is_leap_year(int year)
{
    return ((year%4==0)&&(year%100!=0))||(year%400==0);
}
int month[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
int main_44()
{
    int y,d,m=1;
    cin>>y>>d;
    if (is_leap_year(y))
    {
        month[1]=29;
    }
    for (int i=0; i<12 ; i++ )
    {
        if (d>month[i])
        {
            d-=month[i];
            m++;
        }
        else
        {
            break;
        }
    }
    cout << m << endl;
    cout << d << endl;
    return 0;
}
